//
// Created by 陈成 on 2019/9/22.
//

#ifndef RV32I_CPU_REGBANK_HPP
#define RV32I_CPU_REGBANK_HPP

#include "systemc.h"
#include "Reg.hpp"

template <uint32_t N>
class RegBank {
public:
    RegBank();
    ~RegBank();

    void
    write(uint32_t i, sc_bv<32> v);

    sc_bv<32>
    read(uint32_t i);

private:
    Reg<sc_bv<32> > *r[N];
};

template <uint32_t N>
RegBank<N>::RegBank() {
    for (int i = 0; i < N; ++i)
        r[i] = new Reg<sc_bv<32> >(i);
}

template <uint32_t N>
RegBank<N>::~RegBank() {
    for (int i = 0; i < N; ++i)
        if (r[i]) delete r[i];
}

template <uint32_t N>
void
RegBank<N>::write(uint32_t i, sc_bv<32> v) {
    r[i]->write(v);
}

template <uint32_t N>
sc_bv<32>
RegBank<N>::read(uint32_t i) {
    return (*r)[i].read();
}

#endif //RV32I_CPU_REGBANK_HPP
